package com.yanqu.road.server.logic.recharge.limit.activity;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.config.goods.MallInfo;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.enums.eQualityType;
import com.yanqu.road.entity.mall.LimitBuyResult;
import com.yanqu.road.entity.player.UserPatrons;
import com.yanqu.road.logic.config.GameConfig;
import com.yanqu.road.server.gameplayer.module.patrons.PatronsModule;
import com.yanqu.road.server.gameplayer.module.resource.GoodsResourceModule;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.NormalActivityMgr;
import com.yanqu.road.server.manger.config.PatronsMgr;
import com.yanqu.road.server.protocol.GameErrorCode;

import java.util.List;

public class NewPatronsFundMallLimit extends BaseActivityMallLimit {

    public NewPatronsFundMallLimit(long userId, MallInfo mallInfo, ActivityInfo activityInfo) {
        super(userId, mallInfo, activityInfo);
    }

    @Override
    protected int activityCheck() {
        if(!ActivityMgr.activityInShowTime(activityInfo)){
            return GameErrorCode.E_ACTIVITY_NO_IN_TIME_CANNOT_BUY;
        }
        return 0;
    }

    @Override
    protected boolean isSystemUnLock() {
        return true;
    }

    @Override
    protected LimitBuyResult buyCountLimit() {
        return activityMallCountLimit(player);
    }

    @Override
    protected int logicCheck() {
        if (null == activityInfo) {
            return GameErrorCode.E_SELF_PATRONS_NOT_ACTIVITY;
        }
        //判断是否存在门客
        int patronsId = Integer.parseInt(activityInfo.getParam6());
        UserPatrons userPatrons = player.getModule(PatronsModule.class).getUserPatrons(patronsId);
        if (userPatrons == null) {
            return GameErrorCode.E_SELF_PATRONS_FUND_PATRONS_NOT_EXIST;
        }
        if(userPatrons.getPatronsId() == 102502){//唐三基金加一下联动判断
            if(player.getModule(GoodsResourceModule.class).getPatronsLinkType(userPatrons.getPatronsId()) != 1){
                return GameErrorCode.E_PATRONS_NO_FOUND;
            }
        }
        // 获取门客品质
        int quality = PatronsMgr.getPatronsQuality(userPatrons);
        if(quality < eQualityType.Red.getValue()){
            return GameErrorCode.E_SELF_PATRONS_FUND_PATRONS_NOT_EXIST;
        }
        return 0;
    }
}